package cn.ai.shoes.common.utils;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;

@Component
public class RedisUtils<K,V> {
    @Resource
    //改成泛型
    private RedisTemplate<K,V> redisTemplate;
    public static final Long EXPIRETIME = 5L;

    /**
     *保存字符串
     * @param
     * @return
     */
    public void save(K k, V v, Long expireTime, TimeUnit timeUnit) {
        redisTemplate.opsForValue().set(k, v, expireTime, timeUnit);
    }

    public void save(K k, V v) {
        save(k, v, EXPIRETIME, TimeUnit.MINUTES);
    }

    /**
     * 获取字符串
     * @param
     * @return
     */
    public V get(K k) {
        return redisTemplate.opsForValue().get(k);
    }

    /**
     * 删除验证码
     *
     * @return
     */
    public void del(K str) {
        redisTemplate.delete(str);
    }

}
